//
// This file is part of cpp-lib, a library of C++ functions and classes.
// Cpp-lib is copyright (C) 2004 and onwards, The CPL Interest Group.
// 
// This library is free software; you can redistribute it and/or modify it
// under the terms of the GNU Lesser General Public License as published by
// the Free Software Foundation; either version 2.1 of the License, or (at
// your option) any later version.
// 
// This library is distributed in the hope that it will be useful, but
// WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser
// General Public License for more details.
// 
// You should have received a copy of the GNU Lesser General Public License
// along with this library (see the file COPYING); if not, write to the
// Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
// 02111-1307  USA
//
// $Id$
//


#ifndef CPP_LIB_GEOMETRY_H
#define CPP_LIB_GEOMETRY_H

#include <exception>
#include <stdexcept>
#include <sstream>
#include <vector>
#include <limits>

#include <cassert>
#include <cmath>

#include "cpp-lib/matrix.h"

namespace cpl {

namespace math     {

//
// Transformation spherical <-> cartesian coordinates.
//
// r     ... Radius.
// theta ... Azimuthal angle in the xy-plane from the x-axis (-pi .. pi).
// phi   ... Polar angle from the z-axis (0 .. pi).
//
// Cf. http://mathworld.wolfram.com/SphericalCoordinates.html
//

matrix< double , fixed< 3 , 1 > > const
spherical_to_cartesian( 
  double const& theta ,
  double const& phi
) ;

void cartesian_to_spherical( 
  matrix< double , fixed< 3 , 1 > > const& x ,
  double& r                                  ,
  double& theta                              ,
  double& phi
) ;


// 
// Let S be a sphere with center 0 and x on it's surface.  Return a
// local orthogonal coordinate frame in S with the following properties:
// 
// 1. Its x axis has nonnegative inner product with the z axis of the
//   reference frame.
// 2. Its y axis lies in the xy plane of the reference frame.
// 3. Its z axis points towards 0.
//

matrix< double , fixed< 3 , 3 > > const
sphere_surface_frame( matrix< double , fixed< 3 , 1 > > const& x ) ;


} // namespace math

} // namespace cpl


#endif // CPP_LIB_GEOMETRY_H
